package net.eascn.OrderReader.dao
{
	import flash.events.Event;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.net.URLVariables;
	
	import mx.controls.Alert;
	
	import net.eascn.OrderReader.model.OrderReaderModelLocator;
	
	public class ORProvider
	{
		public function ORProvider()
		{
		}
		
		public function getOrder(id:String):void
		{
			var urlloader:URLLoader = new URLLoader();
			urlloader.addEventListener(Event.COMPLETE , oncompletre);
			var urlq:URLRequest = new URLRequest();
			urlq.url ='http://www.gift4.com.cn/cgi-common/shop/ac-result.php';
			var urlParm:URLVariables= new URLVariables();
			urlParm['action']= 'query_flash_order';
			urlParm['orderId']= id;
			
			urlq.data = urlParm;
			urlq.method = 'post';
			urlloader.load(urlq);
		}
		
		private function oncompletre(event:Event):void
		{
			trace(event.target.data);
			var xml:XML = XML(event.target.data);
			var xmld:XML = xml.orderdata[0];
			var str:String = String(xmld);
			while(str.indexOf('\\')!=-1)
			{
				str = str.replace('\\','');
				
				trace(str.indexOf('\\'));
			}
			var ord:XML = XML(str);
			
			OrderReaderModelLocator.getInstance().currentAlbumXML = ord;
			
			OrderReaderModelLocator.getInstance().dispatchEvent(new Event(Event.COMPLETE));
			Alert.show('订单读取成功');
		}
		
	}
}